home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Inne / Gry / Carnage_Contest / scripts / CC Original / weapons / Plasma Gun.lua < prev    next >
Text File  |  2010-09-23  |  7KB  |  189 lines

  1. --------------------------------------------------------------------------------
  2. -- Weapon Plasma Gun + Projectile Ray
  3. -- Original Carnage Contest Weapon
  4. -- Script by DC, August 2009, www.UnrealSoftware.de
  5. --------------------------------------------------------------------------------
  6.  
  7. -- Setup Tables
  8. if cc==nil then cc={} end
  9. cc.plasmagun={}
  10. cc.plasmagun.ray={}
  11.  
  12. -- Load & Prepare Ressources
  13. cc.plasmagun.gfx_wpn=loadgfx("weapons/plasmagun.bmp")                -- Weapon Image
  14. setmidhandle(cc.plasmagun.gfx_wpn)
  15. cc.plasmagun.gfx_pro=loadgfx("weapons/lasershot.png")                -- Projectile Image
  16. setmidhandle(cc.plasmagun.gfx_pro)
  17. cc.plasmagun.sfx_attack=loadsfx("laser.wav")                        -- Attack Sound
  18. cc.plasmagun.sfx_impact=loadsfx("laserimpact.wav")                    -- Impact Sound
  19.  
  20. --------------------------------------------------------------------------------
  21. -- Weapon: Plasma Gun
  22. --------------------------------------------------------------------------------
  23.  
  24. cc.plasmagun.id=addweapon("cc.plasmagun","Plasma Gun",cc.plasmagun.gfx_wpn,3)    -- Add Weapon (3 uses)
  25. cc.plasmagun.ammo=3                                                    -- 3 Shots
  26.  
  27. function cc.plasmagun.draw()                                        -- Draw
  28.     setblend(blend_alpha)
  29.     setalpha(1)
  30.     setcolor(255,255,255)
  31.     drawinhand(cc.plasmagun.gfx_wpn,6,0)
  32.     -- HUD ammobar
  33.     if cc.plasmagun.ammo-weapon_shots>0 then
  34.         hudammobar(cc.plasmagun.ammo-weapon_shots,cc.plasmagun.ammo)
  35.     end
  36.     -- HUD Crosshair
  37.     if cc.plasmagun.ammo-weapon_shots>0 then
  38.         hudcrosshair(7,3)
  39.     end
  40. end
  41.  
  42. function cc.plasmagun.attack(attack)                                -- Attack
  43.     -- Decrement timer
  44.     if weapon_timer>0 then
  45.         weapon_timer=weapon_timer-1
  46.     end
  47.     -- Attack
  48.     if weapon_shots<cc.plasmagun.ammo and weapon_timer<=0 and attack==1 then
  49.         -- No more weapon switching!
  50.         useweapon(0)
  51.         -- Reset Timer
  52.         weapon_timer=15
  53.         -- Attack
  54.         playsound(cc.plasmagun.sfx_attack)
  55.         weapon_shots=weapon_shots+1
  56.         id=createprojectile(cc.plasmagun.ray.id)
  57.         projectiles[id]={}
  58.         -- Ignore collision with current player at beginning
  59.         projectiles[id].ignore=playercurrent()
  60.         -- Set initial position of projectile
  61.         projectiles[id].x=getplayerx(0)+(7*getplayerdirection(0))-math.sin(math.rad(getplayerrotation(0)))*5.0
  62.         projectiles[id].y=getplayery(0)+3+math.cos(math.rad(getplayerrotation(0)))*5.0
  63.         -- Set speed of projectile
  64.         projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*6.0
  65.         projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*6.0
  66.         -- Timer
  67.         projectiles[id].timer=0
  68.         -- Initial movement
  69.         projectiles[id].x=projectiles[id].x-projectiles[id].sx*1.5
  70.         projectiles[id].y=projectiles[id].y-projectiles[id].sy*1.5
  71.         for i=1,3,1 do
  72.             if cc.plasmagun.ray.move(id)==1 then
  73.                 break
  74.             end
  75.         end
  76.         -- Effects
  77.         recoil(3)
  78.         particle(p_muzzle,getplayerx(0)+(getplayerdirection(0)*7)+math.sin(math.rad(getplayerrotation(0)))*12,getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*12)
  79.         particlecolor(0,255,0)
  80.         particlefadealpha(0.01)
  81.         particle(p_smoke,getplayerx(0)+(getplayerdirection(0)*7)+math.sin(math.rad(getplayerrotation(0)))*12,getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*12)
  82.         particlespeed(-0.2+math.random()*0.4+getwind()*10.0,-1.0+math.random()*0.6)
  83.         particlefadealpha(0.005)
  84.         -- End Turn
  85.         if (weapon_shots>=cc.plasmagun.ammo) then
  86.             endturn()
  87.         end
  88.     end
  89. end
  90.  
  91. --------------------------------------------------------------------------------
  92. -- Projectile: Ray
  93. --------------------------------------------------------------------------------
  94.  
  95. cc.plasmagun.ray.id=addprojectile("cc.plasmagun.ray")            -- Add Projectile
  96.  
  97. function cc.plasmagun.ray.draw(id)                                -- Draw
  98.     -- Setup draw mode
  99.     setblend(blend_light)
  100.     setalpha(1)
  101.     setcolor(0,255,0)
  102.     setscale(1.0,0.5)
  103.     -- Calculate projectile rotation
  104.     setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
  105.     -- Draw projectile
  106.     drawimage(cc.plasmagun.gfx_pro,projectiles[id].x,projectiles[id].y)
  107.     -- Draw Arrow if out of Screen
  108.     outofscreenarrow(projectiles[id].x,projectiles[id].y)
  109. end
  110.  
  111. function cc.plasmagun.ray.update(id)                            -- Update
  112.     -- Particle Tail
  113.     particle(p_lightpuff,projectiles[id].x,projectiles[id].y)
  114.     particlespeed(math.random(-5,5)*0.1,math.random(-5,5)*0.1)
  115.     particlefadealpha(0.05)
  116.     particlesize(math.random(20,40)*0.1,math.random(20,40)*0.1)
  117.     particlecolor(0,255,0)
  118.     -- Move
  119.     cc.plasmagun.ray.move(id)
  120. end
  121.  
  122. function cc.plasmagun.ray.move(id)
  123.     -- Timer (free after 10 secs)
  124.     projectiles[id].timer=projectiles[id].timer+1
  125.     if projectiles[id].timer>500 then
  126.         -- Free projectile
  127.         freeprojectile(id)
  128.         return 1
  129.     end
  130.     rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
  131.     -- Move (in substep loop for optimal collision precision)
  132.     msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/3)
  133.     msubx=projectiles[id].sx/msubt
  134.     msuby=projectiles[id].sy/msubt
  135.     for i=1,msubt,1 do
  136.         projectiles[id].x=projectiles[id].x+msubx
  137.         projectiles[id].y=projectiles[id].y+msuby        
  138.         -- Collision
  139.         if collision(col3x3,projectiles[id].x+math.sin(math.rad(rot))*5,projectiles[id].y-math.cos(math.rad(rot))*5)==1 then
  140.             if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
  141.                 -- Cause damage
  142.                 arealdamage(projectiles[id].x,projectiles[id].y,25,25)
  143.                 -- Destroy terrain
  144.                 terrainexplosion(projectiles[id].x+math.sin(math.rad(rot))*5,projectiles[id].y-math.cos(math.rad(rot))*5,22,2)
  145.                 -- Crater
  146.                 if math.random(1,2)==1 then
  147.                     terrainalphaimage(gfx_crater100,projectiles[id].x+math.sin(math.rad(rot))*5,projectiles[id].y-math.cos(math.rad(rot))*5,math.random(6,9)*0.1,0,25,0)
  148.                 else
  149.                     terrainalphaimage(gfx_crater125,projectiles[id].x+math.sin(math.rad(rot))*5,projectiles[id].y-math.cos(math.rad(rot))*5,math.random(6,9)*0.1,0,25,0)
  150.                 end
  151.                 -- Effects
  152.                 playsound(cc.plasmagun.sfx_impact)
  153.                 particle(p_smoke,projectiles[id].x+math.sin(math.rad(rot))*5,projectiles[id].y-math.cos(math.rad(rot))*5)
  154.                 particlefadealpha(0.006)
  155.                 particle(p_muzzle,projectiles[id].x+math.sin(math.rad(rot))*5,projectiles[id].y-math.cos(math.rad(rot))*5)
  156.                 particlesize(1.5,1.5)
  157.                 particlecolor(0,255,0)
  158.                 particlefadealpha(0.01)
  159.                 for j=1,20,1 do
  160.                     particle(p_lightpuff,projectiles[id].x+math.sin(math.rad(rot))*5,projectiles[id].y-math.cos(math.rad(rot))*5)
  161.                     particlespeed(math.random(-20,20)*0.1,math.random(-20,20)*0.1)
  162.                     particlefadealpha(0.04)
  163.                     particlesize(math.random(40,70)*0.1,math.random(40,70)*0.1)
  164.                     particlecolor(0,255,0)
  165.                 end
  166.                 for i=1,3 do
  167.                     particle(p_spark,projectiles[id].x+math.sin(math.rad(rot))*5,projectiles[id].y-math.cos(math.rad(rot))*5)
  168.                     particlecolor(0,255,0)
  169.                     particlefadealpha(0.01)
  170.                     particlesize(1.5,1.5)
  171.                 end
  172.                 -- Free projectile
  173.                 freeprojectile(id)
  174.                 return 1
  175.             end
  176.         else
  177.             projectiles[id].ignore=0
  178.         end
  179.         -- Water
  180.         if (projectiles[id].y)>getwatery()+5 then
  181.             -- Effects
  182.             playsound(cc.plasmagun.sfx_impact)
  183.             particle(p_smoke,projectiles[id].x,projectiles[id].y)
  184.             -- Free projectile
  185.             freeprojectile(id)
  186.             return 1
  187.         end
  188.     end
  189. end